package com.example.playderdemo;

import android.app.Activity;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.media.MediaPlayer.OnErrorListener;
import android.media.MediaPlayer.OnPreparedListener;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.MediaController;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.VideoView;

public class VideoViewActivity extends Activity {
	
	VideoView videoview;
	  Uri uri;
	 TextView info;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_video_view);
	    info = (TextView) findViewById(R.id.info);
		
	     uri = getIntent().getData();//文件夹，图片浏览器
	     uri=Uri.parse("http://vfx.mtime.cn/Video/2016/07/19/mp4/160719095812990469.mp4");
		
		 videoview= (VideoView) findViewById(R.id.videoview);
		 String savePath = Environment.getExternalStorageDirectory().getAbsolutePath()+"/1moviestest/hello.mp4";
		// videoview.setVideoPath(savePath);
		  videoview.setVideoURI(uri);
		  info.setText(uri.toString());
		 
		 // 设置控制面板，系统自带的
		 videoview.setMediaController(new MediaController(this));
		 
		 // 异步加载准备 好了再播放
		 // 准备好了监听
		 videoview.setOnPreparedListener(new OnPreparedListener() {
			
			@Override
			public void onPrepared(MediaPlayer mp) {
				// TODO Auto-generated method stub
				videoview.start();
			}
		});
		 // 播放出错监听
		 videoview.setOnErrorListener(new OnErrorListener() {
			
			@Override
			public boolean onError(MediaPlayer mp, int what, int extra) {
				// TODO Auto-generated method stub
				return false;
			}
		});
		 // 播放完成
		 videoview.setOnCompletionListener(new OnCompletionListener() {
			
			@Override
			public void onCompletion(MediaPlayer mp) {
			  //切换到下一个
				Toast.makeText(VideoViewActivity.this, "播放完成", Toast.LENGTH_LONG).show();
			}
		});
		 
		 
	
	}
}
